package top.fengleifeng.question;

/**
 * @program: leetcode-test
 * @description:
 * @author: fengleifeng
 * @create: 2020-09-30 17:45
 **/
public class Num1031两个非重叠子数组的最大和 {

    class Solution {
        public int maxSumTwoNoOverlap(int[] A, int L, int M) {
            // 从第几位到第几位
            int[] Larr = getArr(A, L);
            int[] Marr = getArr(A, M);
            //
            int max = get(Larr, Marr, L, M);
            return max;
        }

        private int get(int[] larr, int[] marr, int l, int m) {

            int max = 0;
            for (int i = 0; i < larr.length; i++) {
                for (int j = 0; j < marr.length; j++) {
                    if (i + l < j + 1 || j + m < i + 1) {
                        max = Math.max(max, larr[i] + marr[j]);
                    }
                }
            }
            return max;
        }

        private int[] getArr(int[] A, int num) {
            int[] arr = new int[A.length - num + 1];

            for (int i = 0; i < arr.length; i++) {
                int now = 0;
                for (int j = 0; j < num; j++) {
                    now += A[j + i];
                }
                arr[i] = now;
            }
            return arr;
        }


    }

    public static void main(String[] args) {
        int[] ints = {0, 6, 5, 2, 2, 5, 1, 9, 4};
//        int[] ints = {1,0,3};
        int i = new Num1031两个非重叠子数组的最大和().new Solution().maxSumTwoNoOverlap(ints, 1, 2);
        System.out.println(i);
    }
}
